package com.lul15834.orderfood.activity.manager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.lul15834.orderfood.R;
import com.lul15834.orderfood.activity.manager.adapter.OrderNoAdapter;
import com.lul15834.orderfood.bean.OrderBean;
import com.lul15834.orderfood.bean.OrderDetailBean;
import com.lul15834.orderfood.dao.OrderDao;
import com.lul15834.orderfood.until.Tools;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

//显示所有的订单包括：未完成的
public class OrderNoFinish extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_order_no_finish);
        ListView listView=findViewById(R.id.order_no_listView);
        String account=Tools.getOnAccount(this);
        String sta="1";
        List<OrderBean> list=OrderDao.getAllOrderBySta(account,sta);
        OrderNoAdapter orderNoAdapter=new OrderNoAdapter(this,list);
        if (list==null||list.size()==0){
            listView.setAdapter(null);
        }else {
            listView.setAdapter(orderNoAdapter);
        }
        androidx.appcompat.widget.SearchView searchView=findViewById(R.id.order_no_search);
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener()  {
            @Override
            public boolean onQueryTextSubmit(String query) {
                List<OrderBean> list=OrderDao.getAllOrderBySta(account,sta);
                List<OrderBean> list1=Tools.filterOrder(list,query);
                OrderNoAdapter orderNoAdapter=new OrderNoAdapter(OrderNoFinish.this,list1);
                if (list==null||list.size()==0){
                    listView.setAdapter(null);
                }else {
                    listView.setAdapter(orderNoAdapter);
                }
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                List<OrderBean> list=OrderDao.getAllOrderBySta(account,sta);
                List<OrderBean> list1=Tools.filterOrder(list,newText);
                OrderNoAdapter orderNoAdapter=new OrderNoAdapter(OrderNoFinish.this,list1);
                if (list==null||list.size()==0){
                    listView.setAdapter(null);
                }else {
                    listView.setAdapter(orderNoAdapter);
                }
                return true;
            }
        });
        Toolbar back=findViewById(R.id.order_no_back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(OrderNoFinish.this,Manager.class);
                intent.putExtra("sta","1");
                startActivity(intent);
            }
        });
    }
}